#!/usr/bin/perl -w
use strict;
use DBI;
# run this from in a directory with all the chromosome fastas from UCSC with filenames like
# chr10.fa, chr11.fa, chr12.fa etc... and hard code into this file the name of the genome 
# you are doing and it will add it to the sql.  

my $species = 'mm9';

my $dbh = DBI->connect('DBI:mysql:compressed_genomes', 'x', ''
	           ) || die "Could not connect to database: $DBI::errstr";
chomp(my @filenames = `ls chr*.fa`);
foreach my $filename (@filenames) {
  print "$filename\n";
  open(FAS,"$filename");
  chomp(my @lines = <FAS>);
  close FAS;
  my $header = shift @lines;
  my $chromosome = '';
  if($header=~/>(chr\S+)$/) {
    $chromosome = $1;
  } else { die "not properly formated file\n"; }
  my $sequence = '';
  foreach my $line (@lines) {
    $sequence .= uc($line);
  }
  #print "$chromsome\t$
  $dbh->do("INSERT INTO $species (chromosome, sequence) VALUES('$chromosome',COMPRESS('$sequence'))");
}
$dbh->disconnect();
